package com.qili.base.controller;


import com.qili.util.ExportFileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.activation.MimetypesFileTypeMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

@Controller
@Slf4j
@RequestMapping("/download")
public class DownloadController {

    /**
     * 下载路径
     */
    @Value("${supervisor.downloadPath}")
    private String _sDownloadPath;

    /**
     * @param fileName
     * @Author:Zhangshuo
     * @Description:
     * @Date:15:01 2020-12-07
     */
    @RequestMapping(value = "/xls")
    public void downloadxls(@RequestParam("fileName") String fileName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        if (fileName != null) {
            String AsFileName = _sDownloadPath + "xls/" + fileName;
            ExportFileUtil.exportFile(response,request,AsFileName);
        }
    }
    /**
     * @param fileName
     * @Author:Zhangshuo
     * @Description:
     * @Date:15:01 2020-12-07
     */
    @RequestMapping(value = "/doc")
    public void downloaddoc(@RequestParam("fileName") String fileName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        if (fileName != null) {
            String AsFileName = _sDownloadPath + "doc/" + fileName;
            ExportFileUtil.exportFile(response,request, AsFileName);
        }
    }


}
